T = 33.333

# 

Fs = [
    ["f0", 31.936765],     # genFromMemory
    ["f1", 29.156875],     # resize
    ["f2", 30.493785],     # yolo_preprocess
    ["f3", 25.0771725],    # groupByBatch
    # ["f4", 5.2541575],   # transferToDeviceMemory
    # ["f5", 23.691912],   # yolo_inference
    # ["f6", 26.75222],    # transferToHostMemory
    ["f7_0", 20.117886],   # splitByShape-0
    ["f7_1", 20.117886],   # splitByShape-1
    ["f8_0", 16.927249],   # yolo_postprocess-0
    ["f8_1", 16.927249],   # yolo_postprocess-1
    ["f8_2", 16.927249],   # yolo_postprocess-2
    ["f8_3", 16.927249],   # yolo_postprocess-3
    ["f9", 3.3956725],     # cropWithInput
    ["f10", 2.12385],      # resize
    ["f11", 8.8160225],     # retinanet_preprocess
    ["f12", 4.271880],     # groupByBatch
    # ["f13", 0.6884825],  # transferToDeviceMemory
    # ["f14", 0.7092825],  # retinanet_inference
    # ["f15", 0.650020],   # transferToHostMemory
    ["f16", 1.3280275],    # splitByShape
    ["f17", 5.7501150],    # retinanet_postprocess 
    ["f18", 0.088275],     # cropWithInput
    ["f19", 0.0142575],    # resize
    ["f20", 0.0446675],    # lprnet_preprocess
    ["f21", 0.02206],      # groupByBatch
    # ["f22", 0.01075],    # transferToDeviceMemory
    # ["f23", 0.04283],    # lprnet_inference
    # ["f24", 0.0102375],  # transferToHostMemory
    ["f25", 0.0121575],    # splitByShape
    ["f26", 0.0442075],    # lprnet_postprocess
    ["f27", 0.3958675],    # groupByRequestId
    ["f28", 17.4895845]    # markAndSave
]

Boxes = [["f5", "f14", "f23"],["f4", "f6", "f13", "f15", "f22", "f24"]]
Costs = [24.4440245, 33.333333]

for item in Fs:
    name, cost = item[0],item[1]
    max_index = -1
    max_remain = 0
    for i in range(len(Costs)):
        if cost + Costs[i] <= T:
            remain = T - (cost + Costs[i])
            if remain > max_remain:
                max_index = i
                max_remain = remain
    if max_index == -1:
        # 添加新箱子
        Boxes.append([name])
        Costs.append(cost)
    else:
        Boxes[max_index].append(name)
        Costs[max_index] += cost

for i in Boxes:
    print(i)
print()
for i in Costs:
    print(i)


